有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java常量池条目

查看在某些类上运行javap的输出,我发现了以下奇怪之处:

某些类的常量池包含以下项:

#33 = Utf8               Code
#34 = Utf8               LocalVariableTable
#35 = Utf8               StackMapTable
#36 = Utf8               MethodParameters

为什么这些常量出现在常量池中


共 (1) 个答案

  1. # 1 楼答案

    下列常数

    #33 = Utf8               Code
    #34 = Utf8               LocalVariableTable
    #35 = Utf8               StackMapTable
    #36 = Utf8               MethodParameters
    

    attributes的名称

    For all attributes, the attribute_name_index must be a valid unsigned 16-bit index into the constant pool of the class. The constant_pool entry at attribute_name_index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the name of the attribute.

    您提到的属性具有以下功能:

    • Code属性包含Java虚拟机指令和方法的辅助信息,包括实例初始化方法或类或接口初始化方法
    • LocalVariableTable属性[…]可由调试器在方法执行期间用于确定给定局部变量的值
    • 在通过类型检查进行验证的过程中使用StackMapTable属性
    • MethodParameters属性记录有关方法的形式参数的信息,例如它们的名称